/**
 * Created by zhuyongjie on 2017/10/19.
 */
var dataGridId = "dataList";
$(function () {
    var dataGridId = "dataList";
    var url = basePath + "/history/queryHistoryInstanceList";
    $('#dataList').datagrid('options').url = url;
    $("#dataList").datagrid("reload")
    //$("#dataList").datagrid("loadData", data);
    resizeDataGridSize(dataGridId);
    autoResizeDataGrid(dataGridId);


});

function formatDate(value) {
    return timedate(value,2);
}

/**
 * 删除流程实例
 */
function deleteInstance() {
    var row = $('#dataList').datagrid('getSelected');
    if (row) {
        var processInstanceId = row.id;
        var url = basePath + "/process/"+ processInstanceId + "/deleteProcessInstanceByID";
        layer.confirm('确认删除？', {icon: 3, title:'提示'}, function(index){
            $.ajax({
                type:"POST",
                url:url,
                data:{},
                dataType:"json",
                success:function(data){
                    layer.alert("删除成功",{closeBtn: 0,shift: 4});
                    $("#dataList").datagrid("reload");
                    layer.close(index);
                },
                error : function(data,textstatus){
                    $("#dataList").datagrid("reload");
                    layer.alert("删除失败",{closeBtn: 0,shift: 4});
                    layer.close(index);
                }
            });

        });


    }else{
        layer.alert("请选择",{closeBtn: 0,shift: 4});
    }
}


/**
 * 查看流程图
 */
function viewPic() {
    var row = $('#dataList').datagrid('getSelected');
    if (row) {
        var processInstanceId = row.id;
        var processDefinitionId = row.processDefinitionId;

        var url = basePath + '/resource/diagram-viewer/index.html?processDefinitionId=' + processDefinitionId + '&processInstanceId=' + processInstanceId;

        var clientWidth = document.body.clientWidth * 0.9 + 'px';
        var clientHeight = document.body.clientHeight + 'px';
        parent.layer.open({
            title:"流程图",
            type:2,
            area: [clientWidth,clientHeight],
            content: url,
            maxmin: true
        })

    } else {
        layer.alert("请选择", {closeBtn: 0, shift: 4});
    }
}
